import { getAreaObj } from '@/utils/util'

export const homeOldmanTableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ type: 'selection', reserveSelection: true },
		{
			label: '姓名',
			prop: 'name',
		},
		{ label: '证件号码', prop: 'idCard', plusXing: '2,2' },
		{ label: '户籍所在区', prop: 'crAreaName' },
		{ label: '户籍地址', prop: 'crAddress' },
		{ label: '联系人姓名', prop: 'contactName' },
		{ label: '手机号', prop: 'contactPhone' },
		{ label: '与服务对象关系', prop: 'elderlyRelationshipLabel' },
		{
			label: '操作',
			prop: 'menu',
			width: 200,
			fixed: 'right',
		},
	],
}

export const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共1个：',
					children: [
						{
							label: '《摸底名单信息表》',
							link: true,
							url: 'view_dpElderlyBottoming_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入摸底名单信息',
			description: '',
			uploadTip: '摸底名单信息表',
			active: 2,
			url: 'view_dpElderlyBottoming_import',
			code: 3012,
			rules: [
				{
					label: '导入规则说明:',
					children: [{ label: '(1)导入模式为“覆盖导入”，待导入的服务对象的信息会覆盖平台已存在的' }],
				},
			],
		},
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		// {
		// 	label: '所属区',
		// 	prop: 'areas',
		// 	propName: 'areas_name',
		// 	type: 'AplidAreaSelect',
		// 	span: 8,
		// 	regionGrade: 3,
		// 	checkStrictly: false,
		// 	authArea: true,
		// },
		{
			label: '服务对象',
			prop: 'name',
			type: 'input',
			span: 8,
			rules: [{ required: true, message: '请输入服务对象' }],
		},
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'input',
			span: 8,
			change: (item, form) => {
				if (form.idCard) form.idCard = form.idCard.toUpperCase()
			},
			rules: [{ required: true, message: '请输入证件号码' }],
		},
		{
			label: '户籍地区',
			prop: 'cr_areas',
			propName: 'cr_areas_name',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '户籍地址',
			prop: 'crAddress',
			maxlength: '140',
			showWordLimit: true,
			type: 'text',
			span: 8,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '联系人信息',
			span: 24,
		},
		{
			label: '联系人姓名',
			prop: 'contactName',
			type: 'input',
			span: 8,
		},
		{
			label: '联系人电话 ',
			prop: 'contactTelephone',
			type: 'input',
			span: 8,
		},
		{
			label: '和老人关系',
			prop: 'elderlyRelationship',
			propName: 'elderlyRelationshipLabel',
			type: 'remoteSelect',
			code: 'ELDERLY_RELATIONSHIP',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			showLabel: false,
			placeholder: '如大儿子、二女儿',
			span: 8,
		},
		{
			label: '摸底调研日期',
			prop: 'bottomingDate',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			type: 'date',
			span: 12,
			rules: [{ required: true, message: '请选择摸底调研日期' }],
		},
		{
			label: '摸底人',
			prop: 'gatherUser',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			span: 12,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		// {
		// 	label: '所属区',
		// 	prop: 'areas',
		// 	type: 'AplidAreaSelect',
		// 	regionGrade: 3,
		// 	checkStrictly: false,
		// 	span: 8,
		// },
		{
			label: '服务对象',
			prop: 'name',
			type: 'text',
			span: 8,
		},
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'text',
			span: 8,
		},
		{
			label: '摸底人',
			prop: 'gatherUser',
			type: 'text',
			span: 8,
		},
		{
			label: '摸底调研日期',
			prop: 'bottomingDateBetween',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			type: 'dateBetween',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		// { label: '所属区', prop: 'areaName' },
		{ label: '摸底需求', prop: 'bottomingNeedsLabel' },
		{
			label: '姓名',
			prop: 'name',
		},
		{ label: '证件号码', prop: 'idCard', plusXing: '2,2' },
		{ label: '联系人姓名', prop: 'contactName' },
		{ label: '手机号', prop: 'contactTelephone' },
		{
			label: '摸底调研日期',
			prop: 'bottomingDate',
		},
		{
			label: '摸底人',
			prop: 'gatherUser',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_dpElderlyBottoming_page',
	add: 'view_dpElderlyBottoming_add',
	edit: 'view_dpElderlyBottoming_edit',
	delete: 'view_dpElderlyBottoming_del',
	import: 'view_dpElderlyBottoming_import',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '摸底名单',
	dictcodes: ['BOTTOMING_NEEDS', 'ELDERLY_RELATIONSHIP'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'name',
	exportMqTopic: '/ning/export/',
	importLabel: '导入',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(form.areas, '')
			const areasNameObj: any = getAreaObj(form.areas_name, '')

			const crAreasObj: any = getAreaObj(form.cr_areas, 'cr')
			const crAreasNameObj: any = getAreaObj(form.cr_areas_name, 'cr')

			resolve({
				...form,
				...areasObj,
				...areasNameObj,
				...crAreasObj,
				...crAreasNameObj,
				areas: undefined,
				areasName: undefined,
				cr_areas: undefined,
				cr_areas_name: undefined,
			})
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(query.areas, '')
			resolve({
				...query,
				...areasObj,
				areas: undefined,
			})
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(
				arr.map((item) => {
					const areasObj: any = getAreaObj(item, '', 'set')
					const crAreasObj: any = getAreaObj(item, 'cr', 'set')
					return {
						...item,
						areas: areasObj.areaIds,
						areas_name: areasObj.names,
						cr_areas: crAreasObj.areaIds,
						cr_areas_name: crAreasObj.names,
					}
				})
			)
		})
	},
	dialogConfig: {
		width: '50%',
	},
	searchConfig,
	formConfig,
	detailConfig: formConfig,
	tableConfig,
	importConfig,
}
